def run_algorithm(outlets, user, green, power)
	   data = []
	   preference = user.last.consumption_preference	   
	   #green power factor (GPF)
	   #GPF = (GreenSimulation.where(["logged_at like '%?%'",Time.now.hour]).last/PowerLog.last.power_consumption)
       green_percent = green / power
	   for outlet in outlets
	   	case preference
	   	when preference = 1
	   	 if outlet.priority != 1 and outlet.status == true
	  	    data << outlet.outlet_id
	  	    o = OutletStatus.find(outlet.id)
	  	    o.update_attribute(:status, 0)
	  	 elsif outlet.priority == 1 and outlet.status == false
	  	    data << outlet.outlet_id
	  	    o = OutletStatus.find(outlet.id)
	  	    o.update_attribute(:status, 1)
	  	 end
	  	when preference = 2
	  	  if green_percent >= 0.8 and outlet.priority < 3 and outlet.status == false
	  	    data << outlet.outlet_id
	  	    o = OutletStatus.find(outlet.id)
	  	    o.update_attribute(:status, 1)
	  	  elsif green_percent >= 1 and outlet.priority == 3 and outlet.status == false
	  	    data << outlet.outlet_id
	  	    o = OutletStatus.find(outlet.id)
	  	    o.update_attribute(:status, 1)
	  	  elsif green_percent < 0.8 and outlet.priority == 2 and outlet.status == true
	  	    data << outlet.outlet_id
	  	    o = OutletStatus.find(outlet.id)
	  	    o.update_attribute(:status, 0)
	  	  elsif green_percent < 1 and outlet.priority == 3 and outlet.status == true
	  	    data << outlet.outlet_id
	  	    o = OutletStatus.find(outlet.id)
	  	    o.update_attribute(:status, 0)
	  	  end
	  	when preference = 3
	  	  if green_percent >= 0.4 and outlet.priority < 3 and outlet.status == false
	  	    data << outlet.outlet_id
	  	    o = OutletStatus.find(outlet.id)
	  	    o.update_attribute(:status, 1)
	  	  elsif green_percent >= 0.6 and outlet.priority == 3 and outlet.status == false
	  	    data << outlet.outlet_id
	  	    o = OutletStatus.find(outlet.id)
	  	    o.update_attribute(:status, 1)
	  	  elsif green_percent < 0.4 and outlet.priority > 1 and outlet.status == true
	  	    data << outlet.outlet_id
	  	    o = OutletStatus.find(outlet.id)
	  	    o.update_attribute(:status, 0)
	  	  end
	  	when preference = 4
	  	  if green_percent >= 0.1 and outlet.priority < 3 and outlet.status == false
	  	    data << outlet.outlet_id
	  	    o = OutletStatus.find(outlet.id)
	  	    o.update_attribute(:status, 1)
	  	  elsif green_percent >= 0.3 and outlet.priority == 3 and outlet.status == false
	  	    data << outlet.outlet_id
	  	    o = OutletStatus.find(outlet.id)
	  	    o.update_attribute(:status, 1)
	  	  elsif green_percent < 0.1 and outlet.priority > 1 and outlet.status == true
	  	    data << outlet.outlet_id
	  	    o = OutletStatus.find(outlet.id)
	  	    o.update_attribute(:status, 0)
	  	  end
	  	when preference = 5
	  	    if outlet.status == false
	  	      data << outlet.outlet_id
	  	      o = OutletStatus.find(outlet.id)
	  	    o.update_attribute(:status, 1)
	  	    end
	    end
	   end
	    return data
	end
